import request from "@/utils/request"

//接口:

//5.1 sku图片列表每一项类型
export interface SkuImageItemType {
    id?: number;
	skuId?: number;
	imgName: string;
	imgUrl: string;
	spuImgId?: number;
	isDefault: string;
}


//sku图片列表类型
export type SkuImageListType = SkuImageItemType[]


//5.2 sku属性值列表每一项类型
export interface SkuAttrValueItemType {
    id: number;
	attrId: number;
	valueId: number;
	skuId: number;
	attrName: string;
	valueName: string;
}

//sku属性值列表类型
export type SkuAttrValueListType = SkuAttrValueItemType[]


//sku属性值列表中的每一项
export interface SkuSaleAttrValueItemType {
    id?: number;
	skuId?: number;
	spuId?: number;
	saleAttrValueId?: number;
	saleAttrId?: number;
	saleAttrName: string;
	saleAttrValueName: string;
}

//sku属性值列表类型
export type SkuSaleAttrValueListType = SkuSaleAttrValueItemType[]


//4和5共用, 根据spuId获取sku详细信息的类型
export interface SkuInfoItemType{
    id?: number;
	spuId?: number;
	price: number;
	skuName: string;
	skuDesc: string;
	weight: string;
	tmId?: number;
	category3Id?: number;
	skuDefaultImg: string;
	isSale: number;
	createTime: string;
	skuImageList: null | SkuImageListType;
	skuAttrValueList: null | SkuAttrValueListType;
	skuSaleAttrValueList: null |SkuSaleAttrValueListType;
  }


//6,分页列表的类型
export interface PageListItemType {
    records: SkuInfoItemType[];
    total: number;
    size: number;
    current: number;
    searchCount: boolean;
    pages: number;

}

//根据spuId获取sku列表的类型
export type FindBySpuIdSkuListType = SkuInfoItemType[]

//1,根据skuId下架某个商品
export const requestCancelSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`)
}

//2,根据skuId上架某个商品
export const requestOnlSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`)
}

//3,根据skuId删除某个sku
export const requestDeleteSku = (skuId: number) => {
    return request.get<any, null>(`/admin/product/deleteSku/${skuId}`)
}

//4,根据spuId获取sku列表
export const requestFindBySpuIdSku = (spuId: number) => {
    return request.get<any, SkuInfoItemType>(`/admin/product/findBySpuId/${spuId}`)
}

//5,根据skuId获取相关商品的详细信息
export const requestGetSkuById = (skuId: number) => {
    return request.get<any, SkuInfoItemType>(`/admin/product/getSkuById/${skuId}`)
}

//6,获取分页列表
export const requestPageList = (page: number, limit: number) => {
    return request.get<any, PageListItemType>(`/admin/product/list/${page}/${limit}`)
}

//7,新增sku
export const requestSaveSkuInfo = (skuInfo: SkuInfoItemType) => {
    return request.post<any, null>(`/admin/product/saveSkuInfo`, skuInfo);
  };

